<?php
include('config.php');


function file_fix_name ($name){
    if (strlen($name) != mb_strlen($name,"UTF-8")) {
        return false;
    }
    
    $name_low = strtolower($name);
    $name_fix = str_replace(" ", "_", $name_low);
    return $name_fix;
}

function file_auth_type($name, $file_type) {
    $pos = mb_strrpos($name, ".");
    $type = mb_substr($name, $pos +1);
    if (!in_array($type, $file_type)) {
        echo 'Định dạng không cho phép';
    }
}

if (isset($_POST['btnUp'])){
    $f_name = $_FILES['f_upload']['name'];
    $f_type = $_FILES['f_upload']['type'];
    $f_size = $_FILES['f_upload']['size'];
    $f_temp = $_FILES['f_upload']['tmp_name'];
    echo strlen($f_name) . '<br />' . mb_strlen($f_name,"UTF-8");
    //file_fix_name($f_name);
    file_auth_type($f_name, $file_type);
   // echo $f_name . '<br />' . $f_type. '<br />' . $f_size. '<br />' . $f_temp;
}
?>
<form method="post" enctype="multipart/form-data">
    <fieldset>
        <input type="file" name="f_upload"/>
        <input type="submit" name="btnUp"/>
    </fieldset>
</form>